// 自定义hooks，用来获取天气
import { useState, useEffect } from 'react';
import request from 'umi-request';
export const useWt = () => {
  const [wtNm, set_wtNm] = useState<string>('');
  const [wtTemp, set_wtTemp] = useState<string>('');
  useEffect(() => {
    request
      .get(
        'http://api.k780.com/?app=weather.realtime&weaId=94&ag=today&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json',
      )
      .then((response) => {
        if (response.success === '1') {
          const {
            realTime: { wtNm, wtTemp },
          } = response.result;
          set_wtNm(wtNm);
          set_wtTemp(wtTemp);
        }
      })
      .catch(function (error) {
        console.log(error);
      });
  }, []);
  return [wtNm, wtTemp];
};
